home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / scripts / plot / subplot.m < prev    next >
Text File  |  1996-11-15  |  5KB  |  178 lines

  1. ## Copyright (C) 1996 John W. Eaton
  2. ##
  3. ## This file is part of Octave.
  4. ##
  5. ## Octave is free software; you can redistribute it and/or modify it
  6. ## under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation; either version 2, or (at your option)
  8. ## any later version.
  9. ##
  10. ## Octave is distributed in the hope that it will be useful, but
  11. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. ## General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with Octave; see the file COPYING.  If not, write to the Free
  17. ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  18. ## 02111-1307, USA.
  19.  
  20. ## usage: subplot (rows, columns, index)
  21. ##        subplot (rcn)
  22. ##
  23. ## NOTE: this will work only with gnuplot installed with
  24. ##       multiplot patch (or version 3.6 beta)
  25. ##
  26. ## Sets gnuplot in multiplot mode and plots in location
  27. ## given by index (there are columns X rows subwindows)
  28. ##
  29. ## Input:
  30. ##
  31. ##   rows   : number of rows in subplot grid
  32. ##   columns: number of columns in subplot grid
  33. ##   index  : index of subplot where to make the next plot
  34. ##
  35. ## If only one arg, then it (crn) has to be three digit value
  36. ## specifying the location in digit 1 (rows) and 2 (columns) and digit
  37. ## 3 is the plot index
  38. ##
  39. ## The plot index runs row-wise,i.e., first all the columns in a row
  40. ## are filled and then the next row is filled
  41. ##
  42. ## For example, plot with 4 X 2 grid, will have plot indices running as
  43. ## follows:
  44. ##
  45. ##   -----------------------------------
  46. ##   |        |       |       |        |
  47. ##   |    1   |    2  |    3  |    4   |
  48. ##   |        |       |       |        |
  49. ##   -----------------------------------
  50. ##   |        |       |       |        |
  51. ##   |    5   |    6  |    7  |    8   |
  52. ##   |        |       |       |        |
  53. ##   -----------------------------------
  54. ##
  55.  
  56. ## Author: Vinayak Dutt <Dutt.Vinayak@mayo.EDU>
  57. ## Adapted-By: jwe
  58.  
  59. function subplot (rows, columns, index)
  60.  
  61.   if (! gnuplot_has_multiplot)
  62.     error ("subplot: gnuplot does not appear to support this feature");
  63.   endif
  64.  
  65.   ## global variables to keep track of multiplot options
  66.  
  67.   global multiplot_mode
  68.   global multiplot_xsize multiplot_ysize
  69.   global multiplot_xn multiplot_yn
  70.   global multiplot_xi multiplot_yi
  71.  
  72.   ## This is a real kludge.  We gnuplot should be made so that replot can
  73.   ## be executed while doing multiple plots...
  74.  
  75.   global multiplot_save_auto_replot = automatic_replot
  76.  
  77.   if (nargin != 3 && nargin != 1)
  78.     usage ("subplot (rows, columns, index) or subplot (rcn)");
  79.   endif
  80.  
  81.   if (automatic_replot)
  82.     warning ("turning off automatic replot for multiplot mode");
  83.     multiplot_save_auto_replot = automatic_replot;
  84.     automatic_replot = 0;
  85.   endif
  86.  
  87.   if (nargin == 1)
  88.  
  89.     if (! (is_scalar (rows) && rows >= 0))
  90.       error ("subplot: input rcn has to be a positive scalar");
  91.     endif
  92.  
  93.     tmp = rows;
  94.     index = rem (tmp, 10);
  95.     tmp = (tmp - index) / 10;
  96.     columns = rem (tmp, 10);
  97.     tmp = (tmp - columns) / 10;
  98.     rows = rem (tmp, 10);
  99.  
  100.   elseif (! (is_scalar (columns) && is_scalar (rows) && is_scalar (index)))
  101.     error ("subplot: columns, rows, and index have to be scalars");
  102.   endif
  103.  
  104.   columns = round (columns);
  105.   rows = round (rows);
  106.   index = round (index);
  107.  
  108.   if (index > columns*rows)
  109.     error ("subplot: index must be less than columns*rows");
  110.   endif
  111.  
  112.   if (columns < 1 || rows < 1 || index < 1)
  113.     error ("subplot: columns,rows,index must be be positive");
  114.   endif
  115.  
  116.   if (columns*rows == 1)
  117.  
  118.     ## switching to single plot ?
  119.  
  120.     gset nomultiplot;
  121.     gset size 1, 1;
  122.     gset origin 0, 0;
  123.  
  124.     multiplot_xn = 1;
  125.     multiplot_yn = 1;
  126.     multiplot_mode = 0;
  127.  
  128.     ## Someone may have reset it betweeen calls...
  129.  
  130.     if (! isstr (automatic_replot) && ! automatic_replot)
  131.       automatic_replot = multiplot_save_auto_replot;
  132.     endif
  133.  
  134.   else
  135.  
  136.     ## doing multiplot plots
  137.  
  138.     doagain = 0;
  139.  
  140.     if (exist ("multiplot_mode") != 1)
  141.       doagain = 1;
  142.     elseif (multiplot_mode != 1 || multiplot_xn != columns
  143.         || multiplot_yn != rows)
  144.       doagain = 1;
  145.     endif
  146.  
  147.     if (doagain)
  148.  
  149.       multiplot_mode = 1;
  150.       multiplot_xn = columns;
  151.       multiplot_yn = rows;
  152.       multiplot_xsize = 1.0 ./ columns;
  153.       multiplot_ysize = 1.0 ./ rows;
  154.  
  155.       gset multiplot;
  156.  
  157.       eval (sprintf ("gset size %g, %g", multiplot_xsize, multiplot_ysize));
  158.  
  159.     endif
  160.  
  161.     ## get the sub plot location
  162.  
  163.     yp = fix ((index-1)/columns);
  164.     xp = index - yp*columns - 1;
  165.     multiplot_xi = ++xp;
  166.     multiplot_yi = ++yp;
  167.  
  168.     ## set the origin
  169.  
  170.     xo = (xp - 1.0)*multiplot_xsize;
  171.     yo = (rows - yp)*multiplot_ysize;
  172.  
  173.     eval (sprintf ("gset origin %g, %g", xo, yo));
  174.  
  175.   endif
  176.  
  177. endfunction
  178.